﻿using System.Linq;
using DemoData.Model;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using NUnit.Framework;

namespace DemoDataTest.Model
{
    [TestFixture]
    public class CustomerTest
    {
        [Test]
        public void DemoData_Model_Customer_All_Fail()
        {
            Customer customer = new Customer(string.Empty, string.Empty, string.Empty);

            ValidationResults validationResults = Validation.Validate(customer);
            Assert.IsNotNull(validationResults.FirstOrDefault(vr => vr.Key == "Firstname"));
            Assert.IsNotNull(validationResults.FirstOrDefault(vr => vr.Key == "Lastname"));
        }

        [Test]
        public void DemoData_Model_Customer_Firstname()
        {
            Customer customer = new Customer("SomeFirstName", string.Empty, string.Empty);

            ValidationResults validationResults = Validation.Validate(customer);
            Assert.IsNull(validationResults.FirstOrDefault(vr => vr.Key == "Firstname"));
            Assert.IsNotNull(validationResults.FirstOrDefault(vr => vr.Key == "Lastname"));
        }

        [Test]
        public void DemoData_Model_Customer_Lastname()
        {
            Customer customer = new Customer(string.Empty, string.Empty, "SomeLastName");

            ValidationResults validationResults = Validation.Validate(customer);
            Assert.IsNotNull(validationResults.FirstOrDefault(vr => vr.Key == "Firstname"));
            Assert.IsNull(validationResults.FirstOrDefault(vr => vr.Key == "Lastname"));
        }
    }
}
